class FileModel {
  final int id;
  final int userId;
  final String fileName;
  final String filePath;
  final String fileType;
  final int fileSize;
  final String hash;
  final DateTime uploadTime;
  final DateTime createTime;
  final String extension;
  final String mimeType;
  final String? remark;
  final bool isDeleted;
  final int directoryId;

  FileModel({
    required this.id,
    required this.userId,
    required this.fileName,
    required this.filePath,
    required this.fileType,
    required this.fileSize,
    required this.hash,
    required this.uploadTime,
    required this.createTime,
    required this.extension,
    required this.mimeType,
    this.remark,
    this.isDeleted = false,
    required this.directoryId,
  });

  factory FileModel.fromJson(Map<String, dynamic> json) {
    return FileModel(
      id: json['id'],
      userId: json['user_id'],
      fileName: json['file_name'],
      filePath: json['file_path'],
      fileType: json['file_type'],
      fileSize: json['file_size'],
      hash: json['hash'],
      uploadTime: DateTime.parse(json['upload_time']),
      createTime: DateTime.parse(json['create_time']),
      extension: json['extension'],
      mimeType: json['mime_type'],
      remark: json['remark'],
      isDeleted: json['is_deleted'] ?? false,
      directoryId: json['directory_id'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'user_id': userId,
      'file_name': fileName,
      'file_path': filePath,
      'file_type': fileType,
      'file_size': fileSize,
      'hash': hash,
      'upload_time': uploadTime.toIso8601String(),
      'create_time': createTime.toIso8601String(),
      'extension': extension,
      'mime_type': mimeType,
      'remark': remark,
      'is_deleted': isDeleted,
      'directory_id': directoryId,
    };
  }
}
